package com.usian.admin.kafka.listener;

import com.usian.admin.service.WemediaNewsAutoScanService;
import com.usian.common.constants.user.message.NewsAutoScanConstants;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;
//监听kafka的消息
@Component
public class WemediaNewsAutoListener {

    @Autowired
    WemediaNewsAutoScanService wemediaNewsAutoScanService;

    @KafkaListener(topics = NewsAutoScanConstants.WM_NEWS_AUTO_SCAN_TOPIC)
    public void recevieMessage(ConsumerRecord<?,?> record){
        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);
        if(optional.isPresent()){
            Object value = record.value();
            //当自媒体人发布文章后kafka发消息这边接受到消息进行自动审核
            wemediaNewsAutoScanService.autoScanByMediaNewsId(Integer.valueOf((String) value));
            System.out.println("******kafka消息已经发送了,开始自动审核文章id"+Integer.valueOf((String) value));
            System.out.println("****kafka消息已经发送了,开始自动审核文章id"+Integer.valueOf((String) value));
            System.out.println("*****kafka消息已经发送了,开始自动审核文章id"+Integer.valueOf((String) value));

        }

    }
}